﻿#if NETFX_CORE && !WinRT
#	define WinRT
#endif

    using System;
    using System.ComponentModel;

    using System.Windows;
    using System.Windows.Threading;


namespace DailyFx.UI 
{

    public static class Designer
	{
		/// <summary>
		///		Indicates if in the design mode .
		/// </summary>
		static bool? _ifTrue;

		/// <summary>
		///   Indicates whether or not the framework is in design-time mode.
		/// </summary>
		public static bool IfTrue
		{
			get
			{
				if ( _ifTrue == null )
				{
#if WinRT
                    _ifTrue = DesignMode.DesignModeEnabled;
#elif SILVERLIGHT
                    _ifTrue = DesignerProperties.IsInDesignTool;
#else
					var prop = DesignerProperties.IsInDesignModeProperty;
					_ifTrue = (bool)DependencyPropertyDescriptor.FromProperty( prop, typeof(FrameworkElement) )
																.Metadata.DefaultValue ;

					if ( !_ifTrue.GetValueOrDefault(false) && 
						// in the visual studio editor .
						System.Diagnostics.Process.GetCurrentProcess().ProcessName
													.StartsWith("devenv", StringComparison.Ordinal)
						)
					{
						_ifTrue = true;
					}
#endif
				}
				return _ifTrue.GetValueOrDefault( false );
			}
		}
	}
}
